import numpy as np
# 对称矩阵的特征值分解
A = np.array([[2, 1], [1, 2]])
eigenvalues, eigenvectors = np.linalg.eig(A)

print("特征值:", eigenvalues)
print("特征向量矩阵:")
print(eigenvectors)

# 验证特征值定义: A*v = λ*v
for i in range(len(eigenvalues)):
    v = eigenvectors[:, i]
    λ = eigenvalues[i]
    print(f"A*v_{i} = {np.dot(A, v)}")
    print(f"λ_{i}*v_{i} = {λ*v}")
    print("验证是否相等:", np.allclose(np.dot(A, v), λ*v))